const jwt = require('koa-jwt');
const Router = require('koa-router');
const router = new Router({prefix:'/topics'});
const { find, findById, create, update,checkTopicExist, listFollowers, listQuestions } = require('../controllers/topics');

const { secret } = require('../config');
//登录jwt验证
const auth = jwt({ secret });

router.get('/', find);//获取所有数据
router.post('/', auth, create);//创建数据
router.get('/:id', checkTopicExist, findById);//获取指定数据
router.patch('/:id', auth, checkTopicExist, update);//更新数据
router.get('/:id/followers', checkTopicExist, listFollowers);//获取某个话题的粉丝
router.get('/:id/questions', checkTopicExist, listQuestions);//获取话题的问题列表

module.exports = router;